<?php require '../public/system/headers/headers.php';?>
<?php echo $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/seotoaster.css'); ?>
<?php echo $this->headLink()->appendStylesheet($this->websiteUrl .'system/js/thickbox/thickbox.css'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/jquery/jquery.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/thickbox/thickbox.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/template/template.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.queue.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/fileprogress.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/handlers.js'); ?>
<?php echo $this->headScript(); ?>
<script type="text/javascript">
$(document).ready(function(){ initObjectSWFUpload('<?php echo $this->websiteUrl; ?>', 'templateuploadpic'); });
function initObjectSWFUpload(urlWebsite, buttonId){
    var swfu;
	var settings = {
        flash_url : ""+urlWebsite+"system/js/swfupload/swfupload.swf",
		upload_url: ""+urlWebsite+"sys/backend_swfuploader/uploadtemplate/",
		file_size_limit : "3 MB",
		file_types : "*.gif;*.png;*.jpg",
		file_types_description : "Web Image Files",
		file_upload_limit : 10,
		file_queue_limit : 0,
        custom_settings : {
            progressTarget : "UploadProgress",
			cancelButtonId : "btnCancel"
			},
		debug: false,
        // Button settings
        button_placeholder_id: buttonId,
        button_image_url: ""+urlWebsite+"system/js/swfupload/Chose_Picture.gif",
        button_width: "131",
		button_height: "25",
        button_cursor: SWFUpload.CURSOR.HAND,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		// The event handler functions are defined in handlers.js
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		queue_complete_handler : queueComplete	// Queue plugin event
		};
		swfu = new SWFUpload(settings);
}
function uploadSuccess(file, serverData, responseReceived){
    var fileName = serverData;
    if(fileName.length < 15 && fileName != ''){
        var str = '<img width="182" height="222" src="<?php echo $this->websiteUrl; ?>themes/<?php echo $this->currentTheme; ?>/images/templatepreview/'+fileName+'"/>';
        document.getElementById('templateupdateimage').style.backgroundColor = '#FFFFFF';
        document.getElementById('image_name').value = fileName;
        document.getElementById('templateupdateimage').innerHTML = str;
    }
}
</script>
<div id="seotoaster" class="addtemplate">
<div class="admineditwhat">{%Add template%}</div>
<div class="close_window" onclick="parent.tb_remove();"></div>
<?php if(isset($this->success) && $this->success === true): ?>
    <div class="success" onclick="this.style.display='none';"><?php echo $this->message; ?></div>
<?php endif; ?>
<?php if(isset($this->error) && $this->error === true): ?>
    <div class="errors" onclick="this.style.display='none';"><?php echo $this->message; ?></div>
<?php endif; ?>
<?php if(isset($this->errorElements)):  ?>
    <div class="errors" onclick="this.style.display='none';"><?php echo $this->errorElements;?></div>
<?php endif; ?>
<?php echo $this->form; ?>
<input disabled="disabled" id="btnCancel" value="Cancel All Uploads" onclick="swfu.cancelQueue();" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;" type="button">
<div class="fieldset flash" style="display:none;" id="UploadProgress"></div>
<div class="noimage"><p>{%No Preview%}<br />{%Picture Yet%}<br /><br />180W x 220H</p><div>{%Preview images are helpful when chosing templates%}</div></div>
<div id="templateupdateimage" class="showimage">
<?php if($this->form->image_name->getValue()): ?>
    <img width="182" height="222" src="<?php echo $this->websiteUrl; ?>themes/<?php echo $this->currentTheme; ?>/images/templatepreview/<?php echo $this->form->image_name->getValue(); ?>"/>
<?php endif; ?>
</div>
<input type="hidden" id="hid-main-wsurl" name="hid-main-wsurl" value="<?php echo $this->websiteUrl; ?>" />
</div>
